package com.kun;

import cn.hutool.core.util.ObjUtil;
import com.kun.ext.CustomInterceptor;
import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;

import java.sql.Statement;

/**
 * 数据脱敏
 */
@Intercepts({@Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class})})
public class MybatisInnerResultInterceptor implements Interceptor {


    private CustomInterceptor customInterceptor;

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        Object result = invocation.proceed();
        if (ObjUtil.isEmpty(result)) {
            return result;
        }
        return customInterceptor.doInvokeResult(result);
    }

    public void setCustomInterceptor(CustomInterceptor customInterceptor) {
        this.customInterceptor = customInterceptor;
    }

}
